package com.medicalproject.service.impl;

import com.medical.pojo.Detail;
import com.medical.pojo.type;
import com.medicalproject.mapper.DetailMapper;
import com.medicalproject.mapper.TypeMaper;
import com.medicalproject.service.DetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DetailServiceImpl implements DetailService {
    @Autowired
    DetailMapper detailMapper;
    @Autowired
    TypeMaper typeMaper;
    @Override
    public List<Detail> findAll() {
        List<Detail> list = detailMapper.findAll();
        List<type> list1 = typeMaper.findAll();
        for (Detail detail : list) {
            for (type type : list1) {
                if (detail.getTid()==type.getTypeId()){
                    detail.setTname(type.getTypename());
                }
            }
        }
        return list;
    }

    @Override
    public Detail findById(Integer id) {
        Detail detail = detailMapper.findById(id);
        List<type> list1 = typeMaper.findAll();
        for (type type : list1) {
            if (detail.getTid()==type.getTypeId()){
                detail.setTname(type.getTypename());
            }
        }
        return detail;
    }

    @Override
    public void update(Detail detail) {
        detailMapper.update(detail);
    }

    @Override
    public void add(Detail detail) {
        detailMapper.add(detail);
    }
}
